package com.eling.elcms.travel.service.impl;

import com.eling.elcms.cater.service.IConsumeCardService;
import com.eling.elcms.cater.service.ITravelAccountService;
import com.eling.elcms.core.event.IEventListener;
import com.eling.elcms.core.service.impl.ModelPersistentEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * 员工新怎创建帐户 监听器
 * */
@Service
public class AttendantListener implements IEventListener<ModelPersistentEvent>{

	@Autowired
	private ITravelAccountService travelAccountService;
	
	@Autowired
	private IConsumeCardService consumeCardservice;
	
	@Override
	public void doEvent(ModelPersistentEvent event) {
		
//		if(event.getModel().getClass()==Attendant.class){
//			if(event.getType()==Type.New){
//
//				Attendant attendant = (Attendant) event.getModel();
//				TravelAccount travelAccount = new TravelAccount();
//				travelAccount.setAccountType(AccountType.Attendant);
//				travelAccount.setVersion(0);
//				travelAccount.setAttendant(attendant);
//				travelAccount.setBalance(0.00);
//				travelAccount.setCreatDate(new Date());
//				travelAccount.setStatus(Status.Effective);
//				ConsumeCard consumeCard = new ConsumeCard();
//				attendant.getCno();
//				consumeCard.setCardNumber(attendant.getCno());
//				consumeCard.setStatus(com.eling.elcms.cater.model.ConsumeCard.Status.Free);
//				List<ConsumeCard> query = consumeCardservice.query(consumeCard);
//				if(query!=null && !query.isEmpty()){
//					consumeCard = query.get(0);
//					consumeCard.setStatus(com.eling.elcms.cater.model.ConsumeCard.Status.InUse);
//					consumeCard.setServicePoint(attendant.getServicePoint());
//					consumeCard.setOrganization(attendant.getOrganization());
//					consumeCardservice.save(consumeCard);
//				}else {
//					throw new BusinessException("该卡号不存在或使用中！");
//				}
//				travelAccountService.save(travelAccount);
//			}
//		}
	}

}
